package com.tj.collection.db.dao.impl;

import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.datasource.DataSource;
import com.tj.collection.db.dao.ClQueryDao;
import com.tj.collection.db.entity.business.ClOutboundEntity;
import com.tj.collection.db.entity.business.ClPaidEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2020/2/8
 * Time: 下午5:59
 */
@Repository
public class ClQueryDaoImpl extends AbstractBaseMapper implements ClQueryDao {

    @Override
    public List<ClPaidEntity> selectCollectionPaidList(String merchantCode, Date startDate, Date endDate, Page page) {
        Map<String, Object> params = new HashMap<>();
        params.put("merchantCode", merchantCode);
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        if (page != null) {
            page.setTotalCount(countCollectionPaidList(params));
            params.put("page", page);
        }
        return getSqlSession().selectList(this.getStatement("selectCollectionPaidList"), params);
    }

    @Override
    public Integer countCollectionPaidList(Map<String, Object> params) {
        return getSqlSession().selectOne(this.getStatement("countCollectionPaidList"), params);
    }

    /**
     * 根据逾期天数查询待拨号订单
     *
     * @param merchantCode
     * @param overdueDays
     * @param channelSource
     * @param page
     * @return
     */
    @Override
    public List<ClOutboundEntity> selectOutboundList(String merchantCode, int overdueDays, String channelSource, Page page) {
        Map<String, Object> map = new HashMap<>();
        map.put("merchantCode", merchantCode);
        map.put("overdueDays", overdueDays);
        map.put("channelSource", StringUtils.isEmpty(channelSource) ? null : channelSource);
        map.put("page", page);
        return getSqlSession().selectList(this.getStatement("selectOutboundList"), map);
    }

    @Override
    public Integer countOutboundList(String merchantCode, int overdueDays) {
        Map<String, Object> map = new HashMap<>();
        map.put("merchantCode", merchantCode);
        map.put("overdueDays", overdueDays);
        return getSqlSession().selectOne(this.getStatement("countOutboundList"), map);
    }
}
